\section{Running Example: The Bank Account}
\label{CS}

To illustrate our approach, we present a running example of a Bank Application borrowed from \cite{Barais2008} and written in the \mbox{Saf-Archie} Language (\textsc{Sal}) \cite{Barais2005,Barais2008}. Since our work does not depend on a particular language, we selected \textsc{Sal} because it possesses the core features required for any architectural language. 

\begin{figure}[t]
\includegraphics[width=\columnwidth]{fig/SafArchMM.pdf}%

\vspace{-0.2cm}
\caption{A simplified metamodel for SafArchie \cite{Barais2008}.}%
\label{fig:SAL-MM}%

\vspace{-0.6cm}
\end{figure}

Figure \ref{fig:SAL-MM} presents a simplified metamodel for \textsc{Sal} \cite{Barais2005}. An \textsf{ArchitectureType} in \textsc{Sal} is composed of \textsf{CompositeType}. A \textsf{CompositeType} is hierarchically designed following the so-called Composite pattern: a \textsf{CompositeType} is further composed of either \textsf{PrimitiveComponentType}, or \textsf{CompositeType}. Components are entities with a structure and an interface. Components interface consists of a set of \textsf{PortType}s used for communication between different components, through \textsf{Binding}s. A \textsf{PortType} is either a \textsf{PrimitivePortType} usable only for \textsf{PrimitiveComponentType}s, or a \textsf{DelegatedPortType} usable only for \textsf{CompositeType}s. A \textsf{PrimitivePortType} carries \textsf{Operation}s in an object-oriented flavour (\emph{i.e.}, it has a name, a parameter list, a result and can raise exceptions); whereas \textsf{DelegatedPort}s, as the name suggests, delegate the communication between components and are attached with  \textsf{CompositeType}s . Operations in SAL are either \textsf{Provided}, meaning a component provides a behaviour to other components or \textsf{Required}, meaning a componend requires a behaviour to be able to work. The model designer has to ensure the following constraint: a component port with a \textsf{ProvidedOperation} is binded to another component port with a \textsf{RequiredOperation} with the same signature (be it through a \textsf{DelegatePort}).


%A SafArchie model \cite{Barais2005}is composed of concepts like component, composite, ports and bindings.  A SafArchie component is entity which has a structure and an interface. The components interface is the communication part comprising of set of ports. These ports can be provided or required ports and are used for communication between different components. The ports carry operations. An operation in SafArchie is defined like operations in Object Oriented Programming with name, parameters, result and exceptions. The component model in SafArchie is hierarchical; a component can be composite or a primitive component. The ports in composite are only delegated ports and they link different child components with each other.

Figure \ref{fig:BankM} presents a small Banking Account Application that mangages accounts savings and checkings. It is composed of three \textsf{PrimitiveComponentType}s, \textsf{Savings}, \textsf{Checking} and \textsf{Manager}, and two \textsf{CompositeType}s \textsf{Clients} and \textsf{Bank}. In the \textsf{Manager} component, we find three \textsf{PrimitivePortType}s \textsf{p1} \textsf{p2} and \textsf{p3}, all binded with \textsf{DelegatedPorts}: \textsf{p1} is binded to \textsf{dp1}, which belongs to the \textsf{Bank} composite; \textsf{p2} to \textsf{dp2} in \textsf{Client}; and \textsf{p3} to \textsf{dp3} also in \textsf{Client}. Table \ref{table:map} shows the signature of the operations attached to each \textsf{PrimitivePortType} (since delegated ones do not possess any). Notice how, \emph{e.g.}, \textsf{p2} and \textsf{p4}, which are binded through \textsf{dp2}, both have operation \textsf{\emph{withdraw}}, the first as \textbf{require} and the second as \textbf{provide}.

Ports behaviour is described in the Finite State Process language \cite{1999}, which basically consists of a sequence of messages, each message involving a port number and an associated operation, and a mark for reception (\textsf{?}) and sending (\textsf{!}) of operations.

\medskip\noindent
\begin{boxedminipage}{\columnwidth}
\begin{scriptsize}
	\begin{minipage}[t]{0.5\columnwidth}
		\begin{ttfamily}
			\begin{tabular}{rl}
			Manager =   & P1.?transfer\\
         		      & P2.!withdraw\\
          				& P2.?withdraw\\
          				& P3.!deposit\\
          				& P3.?deposit\\
          				& P1.!transfer
			\end{tabular}
		\end{ttfamily}
	\end{minipage}
	\hfill
	\begin{minipage}[t]{0.48\columnwidth}
		\begin{ttfamily}
			\begin{tabular}{rcl}
			Saving &\!\!\!\!\!\!=\!\!\!\!\!\!& P4.?withdraw\\
         		  && P4.!withdraw
				\\\\\\
         Checking &\!\!\!\!\!\!=\!\!\!\!\!\!& P5.?deposit\\
          			&   & P5.!deposit
			\end{tabular}
		\end{ttfamily}
	\end{minipage}
\end{scriptsize}
\end{boxedminipage}

\medskip\noindent
As an example, consider the most complex behaviour for the \textsf{Manager} component: when receiving a \textsf{transfer} request from the Bank on port \textsf{p1}, it sends a \textsf{withdraw} request on \textsf{p2} for the \textsf{Client} component and waits for its answer, then sends a \textsf{deposit} request on \textsf{p3} for the \textsf{Client}. When receiving its answer, it sends back a \textsf{transfer} answer to the \textsf{Bank}.


%We present an example of a Banking Application that manages the saving and checking of the accounts. As shown in Fig 1, Bank is a composite that is composed of component Manager and composite Clients. The Clients composite has two components saving and checking. Each component has ports represented with a name such as P1,P2 etc. Operations are attached to each port of component as shown in Table 1. There is no operation with a delegated port. The behavior of each component is written in FSP \cite{1999} as shown below. According to the FSP representations the component Manager receives a transfer request at port P1, at port P2 it sends withdraw request, it receives withdraw response, sends deposit request and receives deposit response. Similarly behavior of other components is shown. The Saf-Archie language allows us to write contracts detail using simple OCL constraints. All this information, Software Architecture structure, FSP behaviors and contract detail is used as an input for generating the test model.

\begin{figure}[t]
\centering
\includegraphics[scale=0.45]{fig/Bank.png}

\vspace{-0.2cm}
\caption{Banking Example \cite{Barais2008}}
\label{fig:BankM}

\vspace{-0.7cm}
\end{figure}

%\begin{figure}[ht!]
%\centering
%\includegraphics[scale=0.75]{}
%\caption{Model-driven Testing using BPMN, UML and U2TP}
%\label{mdtB2U}
%\end{figure}


%{\begin{lstlisting}[language= VIA, caption=Architectural Description of Banking Example, label=list:banking]
%Manager= P1.?transfer'P2.!withdraw'P2.?withdraw'P3.!deposit'P3.?deposit'P1.!transfer'Manager.
%Saving:P4.?withdraw'P4.!withdraw
%Checking: P5. ?deposit'P5.!deposit
%Clients: Saving||Checking
%Bank: Manager||Clients
%\end{lstlisting}
%}

\begin{table}[!htp]
\renewcommand{\arraystretch}{1.3}
	\centering
	\begin{scriptsize}
		\begin{tabular}[htp!]{|l|c|}
		\hline
		\textbf{Ports} & \textbf{Operation} \\
		\hline
		\hline
		P1.  & \begin{tabular}{l}
			\textbf{provide} void \emph{transfer}(int amount, AccountId c1, AccountId c2)
		\end{tabular}\\
		\hline
		P2; P3. & \hspace{-0.6cm}\begin{tabular}{l}
			\textbf{require} TransactionId \emph{withdraw}(int amount, AccountId c)\\
			\textbf{require} TransactionId \emph{deposit}(int amount, AccountId c)\\
			\textbf{require} int \emph{getBalance}(AccountId c)
		\end{tabular}\\
		\hline
		P4; P5 & \hspace{-0.6cm}\begin{tabular}{l}
			\textbf{provide} TransactionId \emph{withdraw}(int amount, AccountId c)\\
			\textbf{provide} TransactionId \emph{deposit}(int amount, AccountId c)\\
			\textbf{provide} int \emph{getBalance}(AccountId c)
		\end{tabular}\\
		\hline
		\end{tabular}
	\end{scriptsize}

	\caption{Operations with ports in SafArchie Architecture} 
	\label{table:map}
\end{table}


